package com.example.accountkeeping.dao;

import com.alibaba.fastjson.JSONArray;
import com.example.accountkeeping.Constant;
import com.example.accountkeeping.MyApplication;
import com.example.accountkeeping.R;
import com.example.accountkeeping.model.Assets;
import com.example.accountkeeping.model.Category;
import com.example.accountkeeping.model.Record;
import com.example.accountkeeping.util.SPUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 数据库初始化
 */
public class DBInit {

    //资产数据初始化
    public static void assetsInit(){

        AssetsDao assetsDao = new AssetsDao();

        //资产集合
        List<Assets> assetsList = new ArrayList<>();

        Assets assets1 = new Assets(R.drawable.assets_cash, "现金", 313.00, 1, "");
        Assets assets2 = new Assets(R.drawable.assets_wechat, "微信", 2970.00, 1, "");
        Assets assets3 = new Assets(R.drawable.assets_alipay, "支付宝", 767.00, 1, "");
        Assets assets4 = new Assets(R.drawable.assets_save, "储蓄卡", 16750.00, 1, "");
        Assets assets5 = new Assets(R.drawable.assets_recharge, "充值卡", 0.00, 1,"饭卡，公交卡");
        Assets assets6 = new Assets(R.drawable.assets_receipt, "应收账", 0.00, 1,"别人欠我的钱");

        Assets liability1 = new Assets(R.drawable.assets_credit, "信用卡", 0.00, 2, "");
        Assets liability2 = new Assets(R.drawable.assets_flower, "花呗", 0.00, 2, "");
        Assets liability3 = new Assets(R.drawable.assets_jd, "京东白条", 0.00, 2, "");
        Assets liability4 = new Assets(R.drawable.assets_pay, "应付账", 0.00, 2,"我欠别人的钱");

        assetsList.add(assets1);
        assetsList.add(assets2);
        assetsList.add(assets3);
        assetsList.add(assets4);
        assetsList.add(assets5);
        assetsList.add(assets6);
        assetsList.add(liability1);
        assetsList.add(liability2);
        assetsList.add(liability3);
        assetsList.add(liability4);

        //一份保存到数据库，以便正常crud
        assetsDao.saveAssetsList(assetsList);

        //另一份以json格式保存到SharedPreference中，在添加资产页面初始化list时使用
        String jsonString = JSONArray.toJSONString(assetsList);
        SPUtil.put(MyApplication.getContext(), Constant.TEXT_ASSETS_ADD_LIST, jsonString);
    }

    //资产数据初始化
    public static void categoryInit(){
        CategoryDao categoryDao = new CategoryDao();

        //分类集合
        List<Category> categoryList = new ArrayList<>();

        Category outCategory1 = new Category(R.drawable.category_meishi, "美食", 1);
        Category outCategory2 = new Category(R.drawable.category_fangzu, "房租", 1);
        Category outCategory3 = new Category(R.drawable.category_gouwu, "购物", 1);
        Category outCategory4 = new Category(R.drawable.category_jiaotong, "交通", 1);
        Category outCategory5 = new Category(R.drawable.category_jiaoyu, "教育", 1);
        Category outCategory6 = new Category(R.drawable.category_renqing, "人情往来", 1);
        Category outCategory7 = new Category(R.drawable.category_liangyou, "粮油", 1);
        Category outCategory8 = new Category(R.drawable.category_jiushui, "酒水", 1);
        Category outCategory9 = new Category(R.drawable.category_lvxing, "旅行", 1);
        Category outCategory10 = new Category(R.drawable.category_jianshen, "健身", 1);
        Category outCategory11 = new Category(R.drawable.category_tongxun, "通讯", 1);
        Category outCategory12 = new Category(R.drawable.category_yiliaofeiyong, "医疗", 1);
        Category outCategory13 = new Category(R.drawable.category_jiechu, "借出", 1);



        Category inCategory1 = new Category(R.drawable.category_gongzi, "工资", 2);
        Category inCategory2 = new Category(R.drawable.category_eshoujiaoyi, "二手交易", 2);
        Category inCategory3 = new Category(R.drawable.category_licai, "理财回报", 2);
        Category inCategory4 = new Category(R.drawable.category_jiangjin, "奖金", 2);
        Category inCategory5 = new Category(R.drawable.category_fapiaobaoxiao, "发票报销", 2);
        Category inCategory6 = new Category(R.drawable.category_jieru, "借入", 2);
        Category inCategory7 = new Category(R.drawable.category_shouzhai, "收债", 2);
        Category inCategory8 = new Category(R.drawable.category_yiwaisuode, "意外所得", 2);


        categoryList.add(outCategory1);
        categoryList.add(outCategory2);
        categoryList.add(outCategory3);
        categoryList.add(outCategory4);
        categoryList.add(outCategory5);
        categoryList.add(outCategory6);
        categoryList.add(outCategory7);
        categoryList.add(outCategory8);
        categoryList.add(outCategory9);
        categoryList.add(outCategory10);
        categoryList.add(outCategory11);
        categoryList.add(outCategory12);
        categoryList.add(outCategory13);

        categoryList.add(inCategory1);
        categoryList.add(inCategory2);
        categoryList.add(inCategory3);
        categoryList.add(inCategory4);
        categoryList.add(inCategory5);
        categoryList.add(inCategory6);
        categoryList.add(inCategory7);
        categoryList.add(inCategory8);

        //保存到数据库，以便正常crud
        categoryDao.saveCategoryList(categoryList);


        //图标集合
        List<Integer> categoryImageList = new ArrayList<>();

        int categoryImage1 = R.drawable.category_meishi;
        int categoryImage2 = R.drawable.category_fangzu;
        int categoryImage3 = R.drawable.category_gouwu;
        int categoryImage4 = R.drawable.category_jiaotong;
        int categoryImage5 = R.drawable.category_jiaoyu;
        int categoryImage6 = R.drawable.category_renqing;
        int categoryImage7 = R.drawable.category_liangyou;
        int categoryImage8 = R.drawable.category_jiushui;
        int categoryImage9 = R.drawable.category_lvxing;
        int categoryImage10 = R.drawable.category_jianshen;
        int categoryImage11 = R.drawable.category_tongxun;
        int categoryImage12 = R.drawable.category_yiliaofeiyong;
        int categoryImage13 = R.drawable.category_jiechu;
        int categoryImage14 = R.drawable.category_qita;

        int categoryImage15 = R.drawable.category_yiwaisuode;
        int categoryImage16 = R.drawable.category_gongzi;
        int categoryImage17 = R.drawable.category_eshoujiaoyi;
        int categoryImage18 = R.drawable.category_licai;
        int categoryImage19 = R.drawable.category_jiangjin;
        int categoryImage20 = R.drawable.category_fapiaobaoxiao;
        int categoryImage21 = R.drawable.category_jieru;
        int categoryImage22 = R.drawable.category_shouzhai;

        int categoryImage23 = R.drawable.category_zichan1;
        int categoryImage24 = R.drawable.category_baojian;
        int categoryImage25 = R.drawable.category_baoxiao;
        int categoryImage26 = R.drawable.category_chaoshi;
        int categoryImage27 = R.drawable.category_chongwu;
        int categoryImage28 = R.drawable.category_feijipiao;
        int categoryImage29 = R.drawable.category_huochepiao;
        int categoryImage30 = R.drawable.category_huiyuan;
        int categoryImage31 = R.drawable.category_jiaoyu1;
        int categoryImage32 = R.drawable.category_kafei;
        int categoryImage33 = R.drawable.category_kefuguanli;
        int categoryImage34 = R.drawable.category_paimai;
        int categoryImage35 = R.drawable.category_paishe;
        int categoryImage36 = R.drawable.category_qinzi;
        int categoryImage37 = R.drawable.category_shengxianshuiguo;
        int categoryImage38 = R.drawable.category_waimai;
        int categoryImage39 = R.drawable.category_yishu;
        int categoryImage40 = R.drawable.category_youxi;
        int categoryImage41 = R.drawable.category_yuangongfankui;


        categoryImageList.add(categoryImage1);
        categoryImageList.add(categoryImage2);
        categoryImageList.add(categoryImage3);
        categoryImageList.add(categoryImage4);
        categoryImageList.add(categoryImage5);
        categoryImageList.add(categoryImage6);
        categoryImageList.add(categoryImage7);
        categoryImageList.add(categoryImage8);
        categoryImageList.add(categoryImage9);
        categoryImageList.add(categoryImage10);
        categoryImageList.add(categoryImage11);
        categoryImageList.add(categoryImage12);
        categoryImageList.add(categoryImage13);
        categoryImageList.add(categoryImage14);

        categoryImageList.add(categoryImage15);
        categoryImageList.add(categoryImage16);
        categoryImageList.add(categoryImage17);
        categoryImageList.add(categoryImage18);
        categoryImageList.add(categoryImage19);
        categoryImageList.add(categoryImage20);
        categoryImageList.add(categoryImage21);
        categoryImageList.add(categoryImage22);

        categoryImageList.add(categoryImage23);
        categoryImageList.add(categoryImage24);
        categoryImageList.add(categoryImage25);
        categoryImageList.add(categoryImage26);
        categoryImageList.add(categoryImage27);
        categoryImageList.add(categoryImage28);
        categoryImageList.add(categoryImage29);
        categoryImageList.add(categoryImage30);
        categoryImageList.add(categoryImage31);
        categoryImageList.add(categoryImage32);
        categoryImageList.add(categoryImage33);
        categoryImageList.add(categoryImage34);
        categoryImageList.add(categoryImage35);
        categoryImageList.add(categoryImage36);
        categoryImageList.add(categoryImage37);
        categoryImageList.add(categoryImage38);
        categoryImageList.add(categoryImage39);
        categoryImageList.add(categoryImage40);
        categoryImageList.add(categoryImage41);



        //以json格式保存到SharedPreference中，在添加和修改分类页面时初始化图标列表时使用
        String jsonString = JSONArray.toJSONString(categoryImageList);
        SPUtil.put(MyApplication.getContext(), Constant.TEXT_CATEGORY_IMAGE_LIST, jsonString);
    }
    //记录数据初始化
    public static void recordInit(){
        RecordDao recordDao = new RecordDao();

        //记录集合
        List<Record> recordList = new ArrayList<>();

        Record record1 = new Record(10.0, "2021-12-29", "北门小吃", 1,
                1, R.drawable.category_meishi, "美食", 2, "微信");
        Record record2 = new Record(10.0, "2021-12-28", "零食", 1,
                1, R.drawable.category_meishi, "美食", 3, "支付宝");
        Record record3 = new Record(10.0, "2021-12-26", "化妆品", 1,
                3, R.drawable.category_gouwu, "购物", 1, "现金");
        Record record4 = new Record(10.0, "2021-12-26", "滴滴打车", 1,
                4, R.drawable.category_jiaotong, "交通", 1, "现金");

        Record record5 = new Record(10000.0, "2021-12-24", "十一月份工资", 2,
                14, R.drawable.category_gongzi, "工资", 4, "储蓄卡");
        Record record6 = new Record(100.0, "2021-12-24", "部门采购报销", 2,
                18, R.drawable.category_fapiaobaoxiao, "发票报销", 3, "支付宝");
        Record record7 = new Record(200.0, "2021-12-24", "教辅书", 1,
                5, R.drawable.category_jiaoyu, "教育", 2, "微信");

        Record record8 = new Record(1000.0, "2022-01-01", "定金", 1,
                2, R.drawable.category_fangzu, "房租", 3, "支付宝");
        Record record9 = new Record(700.0, "2022-01-01", "办卡", 1,
                10, R.drawable.category_jianshen, "健身", 4, "储蓄卡");
        Record record10 = new Record(126.0, "2022-01-01", "衣服", 1,
                3, R.drawable.category_gouwu, "购物", 1, "现金");
        Record record11 = new Record(59.9, "2022-01-03", "验核酸", 1,
                12, R.drawable.category_yiliaofeiyong, "医疗", 2, "微信");
        Record record12 = new Record(15000.0, "2022-01-02", "年终奖", 2,
                17, R.drawable.category_jiangjin, "奖金", 4, "储蓄卡");
        Record record13 = new Record(349.0, "2022-01-04", "基金进账", 2,
                16, R.drawable.category_licai, "理财回报", 3, "支付宝");
        Record record14 = new Record(130.0, "2022-01-03", "电话费", 1,
                11, R.drawable.category_tongxun, "通讯", 2, "微信");



        recordList.add(record1);
        recordList.add(record2);
        recordList.add(record3);
        recordList.add(record4);
        recordList.add(record5);
        recordList.add(record6);
        recordList.add(record7);

        recordList.add(record8);
        recordList.add(record9);
        recordList.add(record10);
        recordList.add(record11);
        recordList.add(record12);
        recordList.add(record13);
        recordList.add(record14);

        //保存到数据库，以便正常crud
        recordDao.saveRecordList(recordList);
    }
}
